package downloader

import (
	"log"
	"net/http"
	"io"
	"github.com/axgle/mahonia"
	"github.com/go-crawler/car-prices/fake"
	"time"
	"crypto/tls"
	"fmt"
)

import URL "net/url"

func Get(url string) io.Reader {
	// proxy := func(_ *http.Request) (*url.URL, error) {
    //     return url.Parse("http://127.0.0.1:8087")
	// }

	proxyUrl := "http://113.119.47.199:8118"
	proxy, _ := URL.Parse(proxyUrl)

	transport := &http.Transport{Proxy:http.ProxyURL(proxy),TLSClientConfig: &tls.Config{InsecureSkipVerify: true},}
	fmt.Printf("%v===>%v", transport, time.Second * 50000)

	client := &http.Client{}
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		log.Printf("http.NewRequest err: %v", err)
	}
	
	req.Header.Add("User-Agent", fake.GetUserAgent())
	req.Header.Add("Referer", "https://car.autohome.com.cn")
	req.Header.Set("Cookie", "dper=d8f222986c4f015084af425e0f7758d739b06ebd3a46ce404a3dad4a7b6126cdb4520c8d6edf160d50b44c330d82817763796ae2168775c75ddeb67062f02a42c6e4a812cc293569ac67078828f408c75015caa536a6d54862e4fe4c023c3c65;dplet=1616e3a40d83f4de3c096e17fba572c9;__yjs_duid=1_89c27c09dcc3b19c72313cf2b152fc411637071189027;BCLID_BFESS=7943695692540518209;BDSFRCVID_BFESS=IG_OJeC62Rs7hqcH4MvIM73YoVkBwm5TH6f3zmT7CcK5ICxSP8SIEG0PKU8g0KuM8sPYogKKymOTHrAF_2uxOjjg8UtVJeC6EG0Ptf8g0f5;H_BDCLCKID_SF_BFESS=tR3aQ5rtKRTffjrnhPF305L3XP6-hnjy3bREoCP5WP36qUoPhnQ1KJtzWhjUWh3RymJ42-39LPO2hpRjyxv4y4Ldj4oxJpOJ5e6dhDJpHl51fbbvbURv2tug3-7H3x5dtjTO2bc_5KnlfMQ_bf--QfbQ0hOhqP-jBRIEoCPKfIKbhKKr-R-_-4_tbh_X5-RLfKQnsl7F54nKDp0xMnb8jUk1bP535tRDWT6DWxDX-K5xsMT4QfnbWh8yKabr0MTrQDvy2MON3KJmfbQ2-PJJLtDmD4QP2-biW55L2Mbd-qjP_IoG2Mn8M4bb3qOpBtQmJeTxoUJ25DnJhhCGe6LWj6v0jN0tq-jeHDrKBRbaHJOoDDvXhxvcy4LbKxnxJPne2Jv7Kb3PLJooqqnlKtcGeJJ03-OkbfQ9babTQ-tbBp3k8MQThUn6QfbQ0hOhLPJM526aMKopQR7JOpvwhfnxybDFQRPH-Rv92DQMVU52QqcqEIQHQT3m5-5bbN3ut6IeJnAfVC05JDvsjCtlq47h-tIthl6DqTkXKKOLVhTTXh7keq8CDl55jPkL-PAJWR5ABRkehR7C2hobDD52y5jtDnID3aJm5MPtWm7ObMtyLhTpsIJMyp_WbT8U5tFObhOkaKvia-TEBMb1qljDBT5h2M4qMxtOLR3pWDTm_q5TtUJMeCnTD-Dhe4tX-NFet5DJJM5;s_ViewType=10; _lxsdk_cuid=17da9421254c8-0e728145f47767-1f396452-13c680-17da9421254c8; _lxsdk=17da9421254c8-0e728145f47767-1f396452-13c680-17da9421254c8; _hc.v=24171d8f-ac62-b009-7f34-c9a19a149a7a.1639222219; fspop=test; cy=21; cye=qingdao; _dp.ac.v=08c7f8da-a98e-4459-a826-4919356c54d9; ll=7fd06e815b796be3df069dec7836c3df; ua=dpuser_4110700998; ctu=2c8ce0ef8ded5bdbcde4ebacea5edfda86fb4632cfe3f086c3a47427fcb1ce3c; uamo=13863946940; _lxsdk_s=17da9421255-b8-d83-dea%7C%7C826")
	// fmt.Println("staring.....123")
	resp, err := client.Do(req)

	// fmt.Println("staring.....456")

	if err != nil {
		log.Printf("client.Do err: %v ==end", err)
	}
	
	// fmt.Printf("resp.BodyL:%v", resp.Body)

	mah := mahonia.NewDecoder("utf-8")
	return mah.NewReader(resp.Body)
}